/**
* ============================================================================
* Copyright(C) Skitourenguru GmbH. All Rights Reserved.
* ============================================================================
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
namespace TopoMap.AvalancheUtilities
{
public class RouteIdentifiers
{
///
/// Converts a route id from the 'old region specific scheme' to the 'new generalized scheme'
///
///
/// A route id in the 'old region specific scheme'
/// A route id in the 'new generalized scheme'
///
public static bool getAlpsRouteIdentifier(string countryCollection, int countryId, out int alpsId)
{
alpsId = INVALID_ROUTE_ID;
if (!REGION_ASSIGNMENT.ContainsKey(countryCollection))
{
return false;
}
alpsId = 10 * countryId;
Region region = REGION_ASSIGNMENT[countryCollection];
if (region == Region.IE)
{
// Last digit will be 6=IT
alpsId += (int)Region.IT;
return true;
}
if (region == Region.IW)
{
// Last digit will be 6=IT
alpsId += (int)Region.IT;
alpsId += 1000;
return true;
}
int countryCode = (int)REGION_ASSIGNMENT[countryCollection];
alpsId += countryCode;
return true;
}
///
/// Converts a route id from the 'new generalized scheme' to the 'old region specific scheme'
///
/// A route id in the 'new generalized scheme'
///
/// A route id in the 'old region specific scheme'
///
public static bool getCountryRouteIdentifier(int alpsId, out string countryCollection, out int countryId)
{
countryCollection = null;
countryId = alpsId / 10;
string countrIdString = alpsId.ToString(CultureInfo.InvariantCulture);
int countryCode = alpsId % 10;
if (!Enum.IsDefined(typeof(Region), countryCode))
{
countryId = INVALID_ROUTE_ID;
return false;
}
Region region = (Region)countryCode;
if (region == Region.DE)
{
// Germany got a new numbering scheme starting with winter 2025/2026
countryId = INVALID_ROUTE_ID;
return false;
}
if (region == Region.AP)
{
// Impossible: We want to convert to an id relative to a country
countryId = INVALID_ROUTE_ID;
return false;
}
countryCollection = COLLECTION_ASSIGNMENT[region];
if (region == Region.IT)
{
if (countryId >= 5000)
{
// Theoretically these are Routes of South Tyrol. This case can never happen as IE would be deduced by countryCode
countryId = INVALID_ROUTE_ID;
return false;
}
if (countryId < 1000)
{
countryCollection = COLLECTION_ASSIGNMENT[Region.IE];
return true;
}
if (countryId < 2000)
{
countryCollection = COLLECTION_ASSIGNMENT[Region.IW];
countryId -= 1000;
return true;
}
}
return true;
}
public enum Region
{
AP = 0,
CH = 1,
AT = 2,
FR = 3,
IT = 6,
DE = 7,
SI = 8,
PY = 9,
///
/// Legacy definition
///
IE = 4,
///
/// Legacy definition
///
IW = 5,
}
public static readonly Dictionary COLLECTION_ASSIGNMENT = new Dictionary()
{
{ Region.AP, "Alps" },
{ Region.CH, "Switzerland" },
{ Region.AT, "Austria" },
{ Region.FR, "France" },
{ Region.IT, "Italy" },
{ Region.DE, "Germany" },
{ Region.SI, "Slovenia" },
{ Region.PY, "Pyrenees" },
/// Legacy definition
{ Region.IE, "ItalyEast" },
/// Legacy definition
{ Region.IW, "ItalyWest" },
};
public static readonly Dictionary REGION_ASSIGNMENT = COLLECTION_ASSIGNMENT.ToDictionary(kv => kv.Value, kv => kv.Key);
public readonly static int INVALID_ROUTE_ID = 0;
public readonly static string ALPS_COLLECTION = COLLECTION_ASSIGNMENT[Region.AP];
}
}